using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_EditProductDescriptionAdmin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string js = "<script src=\"../nicEdit.js\" type=\"text/javascript\"></script>";
        js += "<script type=\"text/javascript\">";
        js += "bkLib.onDomLoaded(function() {";
        js += "new nicEditor({fullPanel : true}).panelInstance('" + TextBox1.ClientID + "');";
        js += "});";
        js += "</script>";

       

        ClientScript.RegisterStartupScript(Page.GetType(), "NicEdit", js);

        if (!IsPostBack)
        {
            TextBox1.Text = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).Description;
        }

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.ApplicationPath + "/Admin/EditProductDetailsAdmin.aspx?DepartmentID=" + Request.QueryString["DepartmentID"]
          + "&CategoryID=" + Request.QueryString["CategoryID"] + "&ProductID=" + Request.QueryString["ProductID"]);
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.ApplicationPath + "/Admin/EditProductDescriptionAdmin.aspx?DepartmentID=" + Request.QueryString["DepartmentID"]
          + "&CategoryID=" + Request.QueryString["CategoryID"] + "&ProductID=" + Request.QueryString["ProductID"]);
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.ApplicationPath + "/Admin/EditProductPictureAdmin.aspx?DepartmentID=" + Request.QueryString["DepartmentID"]
         + "&CategoryID=" + Request.QueryString["CategoryID"] + "&ProductID=" + Request.QueryString["ProductID"]);
    }
    protected void goBackLink_Click(object sender, EventArgs e)
    {

        Response.Redirect(Request.ApplicationPath + "/Admin/ProductsAdmin.aspx?DepartmentID=" + Request.QueryString["DepartmentID"]
           + "&CategoryID=" + Request.QueryString["CategoryID"]);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string productid = Request.QueryString["ProductID"];
        string name = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).Name;
        string des = TextBox1.Text.ToString();
        string price = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).Price.ToString();
        string image1 = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).Image1FileName;
        string image2 = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).Image2FileName;
        string catP = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).OnCatalogPromotion.ToString();
        string depP = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).OnDepartmentPromotion.ToString();
        string brandid = CatalogAccess.GetProductBrandID(productid).BrandID.ToString();
        string bask = CatalogAccess.GetProductDetails(Request.QueryString["ProductID"]).Basket.ToString();
        
        bool success = CatalogAccess.UpdateProduct(productid, name, des, price, image1, image2, catP, depP, brandid, bask);

        statusLabel.Text = success ? "Aktualizacja udana" : "Aktualizacja nieudana";
    }
}
